package com.example.demo.controller;

import com.example.demo.entity.StudentView;
import com.example.demo.repository.StudentViewRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/student-view")
@CrossOrigin
public class StudentViewController {

    @Autowired
    private StudentViewRepository studentViewRepository;

    @GetMapping
    public List<StudentView> getAll() {
        return studentViewRepository.findAll();
    }

    @GetMapping("/class/{classId}")
    public List<StudentView> getByClass(@PathVariable Long classId) {
        return studentViewRepository.findByClassId(classId);
    }

    @GetMapping("/major/{majorId}")
    public List<StudentView> getByMajor(@PathVariable Long majorId) {
        return studentViewRepository.findByMajorId(majorId);
    }

    @GetMapping("/college/{collegeId}")
    public List<StudentView> getByCollege(@PathVariable Long collegeId) {
        return studentViewRepository.findByCollegeId(collegeId);
    }
}
